package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         279,
		Discription: "和为n的完全平方数的最小数量",
		Level:       2,
		Labels: map[string]int{
			"动态规划": 1,
		},
	})
}

func NumSquares(n int) int {
	dp := make([]int, n+1)
	dp[1] = 1
	for i := 2; i <= n; i++ {
		dp[i] = i
		for j := 1; j*j <= i; j++ {
			dp[i] = min(dp[i], 1+dp[i-j*j])
		}
	}

	return dp[n]
}
